

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>The config module &mdash; pyamp v1.2 documentation</title>
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '1.2',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="pyamp v1.2 documentation" href="index.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="index.html">pyamp v1.2 documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-pyamp.config">
<span id="the-config-module"></span><h1>The config module<a class="headerlink" href="#module-pyamp.config" title="Permalink to this headline">¶</a></h1>
<p>The config module contains modules pertaining to parsing
configuration options from a configuration file, as well as from the
command line arguments.</p>
<p>This module provides the ability to specify individual configuration
options that should be loaded from either a configuration file, or from
the command line.</p>
<div class="section" id="the-option-class">
<h2>The Option class<a class="headerlink" href="#the-option-class" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="pyamp.config.Option">
<em class="property">class </em><tt class="descclassname">pyamp.config.</tt><tt class="descname">Option</tt><big>(</big><em>name</em>, <em>defaultValue=None</em>, <em>typeFn=None</em>, <em>commandLine=False</em>, <em>acceptedValues=None</em>, <em>caseSensitive=True</em><big>)</big><a class="headerlink" href="#pyamp.config.Option" title="Permalink to this definition">¶</a></dt>
<dd><p>The Option class encapsulates a single configuration option. It contains
the name of the option, a default value for the option, as well as a
function to convert the option into a specific type.</p>
<ul class="simple">
<li>name &#8211; The name of the option</li>
<li>defaultValue &#8211; The default value for this option</li>
<li>typeFn &#8211; The function to convert the value to a specific type</li>
<li>commandLine &#8211; True to be a command line option</li>
<li>acceptedValues &#8211; The list of accepted values</li>
<li>caseSensitive &#8211; True if the accepted values are case sensitive</li>
</ul>
<dl class="method">
<dt id="pyamp.config.Option.convert">
<tt class="descname">convert</tt><big>(</big><em>value</em><big>)</big><a class="headerlink" href="#pyamp.config.Option.convert" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert the given value into the expected type for this Option.</p>
<ul class="simple">
<li>value &#8211; The value to convert</li>
</ul>
</dd></dl>

<dl class="method">
<dt id="pyamp.config.Option.getAcceptedValues">
<tt class="descname">getAcceptedValues</tt><big>(</big><big>)</big><a class="headerlink" href="#pyamp.config.Option.getAcceptedValues" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the list of accepted values for this Option.</p>
</dd></dl>

<dl class="method">
<dt id="pyamp.config.Option.getDefaultValue">
<tt class="descname">getDefaultValue</tt><big>(</big><big>)</big><a class="headerlink" href="#pyamp.config.Option.getDefaultValue" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the default value for this Option.</p>
</dd></dl>

<dl class="method">
<dt id="pyamp.config.Option.getName">
<tt class="descname">getName</tt><big>(</big><big>)</big><a class="headerlink" href="#pyamp.config.Option.getName" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the name of this Option.</p>
</dd></dl>

<dl class="method">
<dt id="pyamp.config.Option.isAcceptedValue">
<tt class="descname">isAcceptedValue</tt><big>(</big><em>value</em><big>)</big><a class="headerlink" href="#pyamp.config.Option.isAcceptedValue" title="Permalink to this definition">¶</a></dt>
<dd><p>Determine if the given value is one of the accepted values for
this Option.</p>
<ul class="simple">
<li>value &#8211; The value to check</li>
</ul>
</dd></dl>

<dl class="method">
<dt id="pyamp.config.Option.isCommandLine">
<tt class="descname">isCommandLine</tt><big>(</big><big>)</big><a class="headerlink" href="#pyamp.config.Option.isCommandLine" title="Permalink to this definition">¶</a></dt>
<dd><p>Determine if this Option is configurable through the command
line.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="the-cloption-class">
<h2>The ClOption class<a class="headerlink" href="#the-cloption-class" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="pyamp.config.ClOption">
<em class="property">class </em><tt class="descclassname">pyamp.config.</tt><tt class="descname">ClOption</tt><big>(</big><em>name</em>, <em>abbr=None</em>, <em>defaultValue=None</em>, <em>action=None</em>, <em>optionType=None</em>, <em>helpText=None</em>, <em>acceptedValues=None</em>, <em>caseSensitive=True</em><big>)</big><a class="headerlink" href="#pyamp.config.ClOption" title="Permalink to this definition">¶</a></dt>
<dd><p>The ClOption class encapsulates an <a class="reference internal" href="#pyamp.config.Option" title="pyamp.config.Option"><tt class="xref py py-class docutils literal"><span class="pre">Option</span></tt></a> that is configurable
through the command line as well as through a configuration file.</p>
<ul class="simple">
<li>name &#8211; The name of the option</li>
<li>abbr &#8211; The abbreviated name</li>
<li>defaultValue &#8211; The default value for this option</li>
<li>action &#8211; The action used for this option</li>
<li>optionType &#8211; The type of the option</li>
<li>helpText &#8211; The help text to display</li>
<li>acceptedValues &#8211; The list of accepted values</li>
<li>caseSensitive &#8211; True if the accepted values are case sensitive</li>
</ul>
<dl class="method">
<dt id="pyamp.config.ClOption.addOption">
<tt class="descname">addOption</tt><big>(</big><em>parser</em><big>)</big><a class="headerlink" href="#pyamp.config.ClOption.addOption" title="Permalink to this definition">¶</a></dt>
<dd><p>Add the command line option to the command line parser.</p>
<ul class="simple">
<li>parser &#8211; The command line parser</li>
</ul>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="the-configfile-class">
<h2>The ConfigFile class<a class="headerlink" href="#the-configfile-class" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="pyamp.config.ConfigFile">
<em class="property">class </em><tt class="descclassname">pyamp.config.</tt><tt class="descname">ConfigFile</tt><big>(</big><em>configurationFile=None</em>, <em>options=None</em>, <em>variables=None</em>, <em>logger=None</em><big>)</big><a class="headerlink" href="#pyamp.config.ConfigFile" title="Permalink to this definition">¶</a></dt>
<dd><p>The ConfigFile class is responsible for parsing a configuration file
with the given dictionary of sections and options, and variables.</p>
<p>The ConfigFile class takes a dictionary of options which map the
configuration section names to the list of configuration <a class="reference internal" href="#pyamp.config.Option" title="pyamp.config.Option"><tt class="xref py py-class docutils literal"><span class="pre">Option</span></tt></a>
objects associated with that section. It also takes a dictionary of
variables mapping the name of the variable to the value for the variable.
The variable names can then be used in a configuration file by adding
a $ before the variable name. This value will then be replaced with the
value assigned in the variables dictionary.</p>
<p>This class implements the <tt class="xref py py-class docutils literal"><span class="pre">Loggable</span></tt> interface. This class uses the
<a class="reference external" href="http://docs.python.org/library/configparser.html#ConfigParser" title="(in Python v2.7)"><tt class="docutils literal"><span class="pre">ConfigParser</span></tt></a> module to parse the configuration file, and thus parses
configuration files of the same format.</p>
<ul class="simple">
<li>configurationFile &#8211; The configuration file to load</li>
<li>options &#8211; The dictionary of supported options</li>
<li>variables &#8211; The dictionary of supported variables</li>
<li>logger &#8211; The logger</li>
</ul>
<dl class="method">
<dt id="pyamp.config.ConfigFile.get">
<tt class="descname">get</tt><big>(</big><em>section</em>, <em>option</em>, <em>defaultValue=None</em><big>)</big><a class="headerlink" href="#pyamp.config.ConfigFile.get" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the value of the given configuration option from the given
section.</p>
<ul class="simple">
<li>section &#8211; The section name</li>
<li>option &#8211; The option</li>
<li>defaultValue &#8211; The default value if the option does not exist</li>
</ul>
</dd></dl>

<dl class="method">
<dt id="pyamp.config.ConfigFile.getSettings">
<tt class="descname">getSettings</tt><big>(</big><big>)</big><a class="headerlink" href="#pyamp.config.ConfigFile.getSettings" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the settings dictionary.</p>
</dd></dl>

<dl class="method">
<dt id="pyamp.config.ConfigFile.parse">
<tt class="descname">parse</tt><big>(</big><em>filename</em><big>)</big><a class="headerlink" href="#pyamp.config.ConfigFile.parse" title="Permalink to this definition">¶</a></dt>
<dd><p>Parse a configuration file.</p>
<ul class="simple">
<li>filename &#8211; The configuration file to parse</li>
</ul>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="the-optionsparser-class">
<h2>The OptionsParser class<a class="headerlink" href="#the-optionsparser-class" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="pyamp.config.OptionsParser">
<em class="property">class </em><tt class="descclassname">pyamp.config.</tt><tt class="descname">OptionsParser</tt><big>(</big><em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#pyamp.config.OptionsParser" title="Permalink to this definition">¶</a></dt>
<dd><p>The OptionsParser class is responsible for parsing command line and
configuration file options and providing the ability to get the value of a
given option.</p>
<p>This class implements the <a class="reference internal" href="patterns.html#pyamp.patterns.Borg" title="pyamp.patterns.Borg"><tt class="xref py py-class docutils literal"><span class="pre">pyamp.patterns.Borg</span></tt></a> design pattern and
also implements the <a class="reference internal" href="logging.html#pyamp.logging.Loggable" title="pyamp.logging.Loggable"><tt class="xref py py-class docutils literal"><span class="pre">pyamp.logging.Loggable</span></tt></a> interface.</p>
<ul class="simple">
<li>args &#8211; The arguments</li>
<li>kwargs &#8211; The keyword arguments</li>
</ul>
<dl class="attribute">
<dt id="pyamp.config.OptionsParser.ClOptions">
<tt class="descname">ClOptions</tt><a class="headerlink" href="#pyamp.config.OptionsParser.ClOptions" title="Permalink to this definition">¶</a></dt>
<dd><p>This property contains the list of options that are only configurable
via the command line.</p>
</dd></dl>

<dl class="attribute">
<dt id="pyamp.config.OptionsParser.Options">
<tt class="descname">Options</tt><a class="headerlink" href="#pyamp.config.OptionsParser.Options" title="Permalink to this definition">¶</a></dt>
<dd><p>This property contains a dictionary mapping section names to the list of
options contained within that section. Options must be a subclass of
the <a class="reference internal" href="#pyamp.config.Option" title="pyamp.config.Option"><tt class="xref py py-class docutils literal"><span class="pre">Option</span></tt></a> class. These are the sections and options that will
be loaded from the configuration file and the command line arguments.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Any <a class="reference internal" href="#pyamp.config.ClOption" title="pyamp.config.ClOption"><tt class="xref py py-class docutils literal"><span class="pre">ClOption</span></tt></a> objects that are given will be
configurable via the configuration file and from the command line.</p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="pyamp.config.OptionsParser.Variables">
<tt class="descname">Variables</tt><a class="headerlink" href="#pyamp.config.OptionsParser.Variables" title="Permalink to this definition">¶</a></dt>
<dd><p>This property contains a dictionary mapping variable names
to their respective values. These variables can be used
within the configuration file and will be replaced by the
assigned values.</p>
<p>Variables can be used in the configuration file by appending a dollar sign
before the name of the variable. The variable will then replaced with its
value prior to parsing the file.</p>
<p>Example:</p>
<div class="highlight-python"><pre># $HOME will be replaced with the user's home directory before parsing
[Section]
Var = $HOME</pre>
</div>
</dd></dl>

<dl class="classmethod">
<dt id="pyamp.config.OptionsParser.get">
<em class="property">classmethod </em><tt class="descname">get</tt><big>(</big><em>section</em>, <em>optionName</em>, <em>defaultValue=None</em><big>)</big><a class="headerlink" href="#pyamp.config.OptionsParser.get" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the value of an option from the given section.</p>
<ul class="simple">
<li>section &#8211; The name of the section</li>
<li>optionName &#8211; The name of the option</li>
<li>defaultValue &#8211; The default value if the option does not exist</li>
</ul>
</dd></dl>

<dl class="classmethod">
<dt id="pyamp.config.OptionsParser.getCl">
<em class="property">classmethod </em><tt class="descname">getCl</tt><big>(</big><em>optionName</em>, <em>defaultValue=None</em><big>)</big><a class="headerlink" href="#pyamp.config.OptionsParser.getCl" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the value of a command line option.</p>
<ul class="simple">
<li>optionName &#8211; The name of the command line option</li>
<li>defaultValue &#8211; The default value if the option does not exist</li>
</ul>
</dd></dl>

<dl class="method">
<dt id="pyamp.config.OptionsParser.init">
<tt class="descname">init</tt><big>(</big><em>logger=None</em><big>)</big><a class="headerlink" href="#pyamp.config.OptionsParser.init" title="Permalink to this definition">¶</a></dt>
<dd><p>Override the <a class="reference internal" href="patterns.html#pyamp.patterns.Borg" title="pyamp.patterns.Borg"><tt class="xref py py-class docutils literal"><span class="pre">pyamp.patterns.Borg</span></tt></a> init function.</p>
<ul>
<li><dl class="first docutils">
<dt>logger &#8211; The <a class="reference internal" href="logging.html#pyamp.logging.Logger" title="pyamp.logging.Logger"><tt class="xref py py-class docutils literal"><span class="pre">pyamp.logging.Logger</span></tt></a> or</dt>
<dd><p class="first last"><a class="reference internal" href="logging.html#pyamp.logging.LogData" title="pyamp.logging.LogData"><tt class="xref py py-class docutils literal"><span class="pre">pyamp.logging.LogData</span></tt></a> object</p>
</dd>
</dl>
</li>
</ul>
</dd></dl>

<dl class="method">
<dt id="pyamp.config.OptionsParser.parse">
<tt class="descname">parse</tt><big>(</big><em>argv</em>, <em>filename</em><big>)</big><a class="headerlink" href="#pyamp.config.OptionsParser.parse" title="Permalink to this definition">¶</a></dt>
<dd><p>Parse the command line options, and the configuration file.</p>
<ul class="simple">
<li>argv &#8211; The command line options</li>
<li>filename &#8211; The path to the configuration file</li>
</ul>
</dd></dl>

<dl class="classmethod">
<dt id="pyamp.config.OptionsParser.set">
<em class="property">classmethod </em><tt class="descname">set</tt><big>(</big><em>section</em>, <em>optionName</em>, <em>value</em><big>)</big><a class="headerlink" href="#pyamp.config.OptionsParser.set" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the value of an option from the given section.</p>
<ul class="simple">
<li>section &#8211; The name of the section</li>
<li>optionName &#8211; The name of the option</li>
<li>value &#8211; The value</li>
</ul>
</dd></dl>

<dl class="classmethod">
<dt id="pyamp.config.OptionsParser.setCl">
<em class="property">classmethod </em><tt class="descname">setCl</tt><big>(</big><em>optionName</em>, <em>value</em><big>)</big><a class="headerlink" href="#pyamp.config.OptionsParser.setCl" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the value of a command line option.</p>
<ul class="simple">
<li>optionName &#8211; The name of the command line option</li>
<li>value &#8211; The value</li>
</ul>
</dd></dl>

<dl class="method">
<dt id="pyamp.config.OptionsParser.setLogger">
<tt class="descname">setLogger</tt><big>(</big><em>logger</em>, <em>color=0</em><big>)</big><a class="headerlink" href="#pyamp.config.OptionsParser.setLogger" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the logger for the OptionsParser.</p>
<ul>
<li><dl class="first docutils">
<dt>logger &#8211; The <a class="reference internal" href="logging.html#pyamp.logging.Logger" title="pyamp.logging.Logger"><tt class="xref py py-class docutils literal"><span class="pre">pyamp.logging.Logger</span></tt></a> or</dt>
<dd><p class="first last"><a class="reference internal" href="logging.html#pyamp.logging.LogData" title="pyamp.logging.LogData"><tt class="xref py py-class docutils literal"><span class="pre">pyamp.logging.LogData</span></tt></a> object</p>
</dd>
</dl>
</li>
</ul>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="module-pyamp.config.conversions">
<span id="the-conversions-module"></span><h2>The conversions module<a class="headerlink" href="#module-pyamp.config.conversions" title="Permalink to this headline">¶</a></h2>
<p>Contains various type conversion functions for converting configuration
options into specific types.</p>
<dl class="function">
<dt id="pyamp.config.conversions.logLevel">
<tt class="descclassname">pyamp.config.conversions.</tt><tt class="descname">logLevel</tt><big>(</big><em>value</em><big>)</big><a class="reference internal" href="_modules/pyamp/config/conversions.html#logLevel"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyamp.config.conversions.logLevel" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the log level type from the string representation of
the log level (DEBUG, INFO, WARN, or ERROR).</p>
<ul class="simple">
<li>value &#8211; The string value for the desired log level</li>
</ul>
</dd></dl>

<dl class="function">
<dt id="pyamp.config.conversions.string">
<tt class="descclassname">pyamp.config.conversions.</tt><tt class="descname">string</tt><big>(</big><em>value</em><big>)</big><a class="reference internal" href="_modules/pyamp/config/conversions.html#string"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyamp.config.conversions.string" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert the given value into a string type &#8211; being sure to remove
any quotations that may be around the string.</p>
<ul class="simple">
<li>value &#8211; The value to convert into a string</li>
</ul>
</dd></dl>

<dl class="function">
<dt id="pyamp.config.conversions.boolean">
<tt class="descclassname">pyamp.config.conversions.</tt><tt class="descname">boolean</tt><big>(</big><em>value</em><big>)</big><a class="headerlink" href="#pyamp.config.conversions.boolean" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert the given value into a boolean type.</p>
<ul class="simple">
<li>value &#8211; The value to convert into a string</li>
</ul>
</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">The config module</a><ul>
<li><a class="reference internal" href="#the-option-class">The Option class</a></li>
<li><a class="reference internal" href="#the-cloption-class">The ClOption class</a></li>
<li><a class="reference internal" href="#the-configfile-class">The ConfigFile class</a></li>
<li><a class="reference internal" href="#the-optionsparser-class">The OptionsParser class</a></li>
<li><a class="reference internal" href="#module-pyamp.config.conversions">The conversions module</a></li>
</ul>
</li>
</ul>

  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="_sources/config.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="index.html">pyamp v1.2 documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2012, Brett Ponsler.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.1.
    </div>
  </body>
</html>